Controlling the Light Emitting Diode (LED) with a push button
INSTRUCTIONS
Step-1(Info.)
1.)
Source
2.)
Target
Note:
Make Connections First, Then move to the code Compilation
Step-2 (Connections)
1.)Drag and drop BreadBoard,Arduino and all other Components first.
2.)Connect
Pin 1
with
Pin 5
of breadboard..
3.)Connect
source Pin
of resister2 with
Pin 7
of Breadboard.. And
target Pin
of Resister2 with
Pin 2
of Breadboard
4.)Connect
Pin 8
of breadboard with
Pin 2
of Arduino.
5.)Connect
Gnd Pin
of Arduino with
Pin 4
of Breadboard & Connect
Pin (5V)
of arduino with
Pin 3
of Breadboard.
6.)Connect
led
with a 1k ohm
Resister1
and connect that register to
Pin 11
of arduino and ground the
negative Pin
of LED.
7.)Click on
"CHECK"
button to check the connections.
Step-3 (Code Compilation)
1.) Set the ledState to
"LOW"
first
2.) Set the pinMode of ledPin as
"OUTPUT"
3.) Set the pinMode of buttonPin as
"INPUT"
4.) Set the buttonState as
"HIGH"
5.) Click on
"COMPILE"
button and compile the simulation.
6.) Click on Push button to blink the LED.
Components
Push Button
Resister 1
LED
Resister 2
Arduino
BreadBoard
5
7
8
1
2
3
4
BreadBoard
LED
Push Button
Name :
Resister2
Value
1k ohm Resister
Name :
Resister1
Value
1k ohm Resister
Arduino UNO
Code Compiler
int
buttonPin = 2;
int
ledPin = 11;
// Variables
int
buttonState = 0;
int
lastButtonState = 0;
int
ledState =
;
void
setup() {
pinMode
(ledPin,
);
pinMode
(buttonPin,
);
}
void
loop() {
buttonState =
digitalRead
(buttonPin);
if
(buttonState != lastButtonState) {
if
(buttonState ==
) {
ledState = !ledState;
digitalWrite
(ledPin, ledState);
}
delay
(50);
}
lastButtonState = buttonState;
}
CHECK
RESET
COMPILE
PRINT
© 2024 | Virtual Labs, IIT Roorkee